# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/msm8939_defconfig

pkgname=linux-huawei-kiwi
pkgver=5.9_rc7
pkgrel=1
pkgdesc="Huawei Honor 5X kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="huawei-kiwi"
url="https://git.sr.ht/~bo41/msm8939-mainline-linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev installkernel flex openssl-dev perl"

_repository="msm8939-mainline-linux"
_commit="36b820fdeba148f05eb1eaf9cbea94050ce6cbe9"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::$url/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir"/usr/share/dtb
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="3802f0bc6fab81a6fff0e48800fd2c7ce96ab8ab1b068eb54f2a402e3a4edb77a97d21af39392588a42a48abace19eed5bc3bbaa83598df5eba4df3b43010011  linux-huawei-kiwi-36b820fdeba148f05eb1eaf9cbea94050ce6cbe9.tar.gz
a0fc476a7af2926a870285d3a68bea361284cd062c7f8bdb15fc2292f949c3ce8c30760056229cbbc294ecd28b25c295420baf850aefde5941477d5a98ec0e34  config-huawei-kiwi.aarch64"
